package com.kfm.pm;

public class TryDemo {
    public static void main(String[] args) {
        try {
            testThree();
        } catch (Exception e3) {
//            System.out.println(e.getCause().getMessage());
            System.out.println(e3.getCause().getCause().getMessage());
//            e.printStackTrace(); //
        }
    }

    public static void testOne() throws MyException {
        throw new MyException("我是一个异常");
    }

    public static void testTwo() throws Exception {
        try {
            testOne();
        } catch (Exception e1) {
//            throw new Exception("我是新产生的异常1", e);
            Exception e2 = new Exception("我是新产生的异常1");
            e2.initCause(e1);
            throw e2;
        }
    }

    public static void testThree() throws Exception {
        try {
            testTwo();
        } catch (Exception e2) {
//            throw new Exception("我是新产生的异常2", e);
            Exception e3 = new Exception("我是新产生的异常2");
            e3.initCause(e2);
            throw e3;
        }
    }
}

class MyException extends Exception {

    public MyException(String message) {
        super(message);
    }
}
